package cn.edu.ruc.cloudcomputing.book.zookeeperTest;

import java.io.IOException;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs.Ids;

/**
 * 
 * @author JunJie.Wang
 * 创建节点
 */
public class CreateGroup extends ZookeeperInstance {

	//创建组  参数：groupPath
	public void createPNode(String groupPath)throws KeeperException,InterruptedException{
		
		/**
		 * 参数： 路径、 znode内容，ACL(访问控制列表)、 znode创建类型
		 * znode创建类型(CreateMode)：PERSISTENT持久化节点PERSISTENT_SEQUENTIAL,顺序自动编号持久化节点，这种节点会根据当前已存在的节点数自动加 1,EPHEMERAL临时节点， 客户端session超时这类节点就会被自动删除EPHEMERAL_SEQUENTIAL临时自动编号节点
		 */
		String cGroupPath = zk.create(groupPath, "group".getBytes(), Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT);
		System.out.println("创建的组路径："+cGroupPath);
	}
	
	public static void main(String[] args) throws IOException, KeeperException, InterruptedException{
		CreateGroup cg = new CreateGroup();
		cg.createZKInstance();
		cg.createPNode("/ZKGroup08030002");
		cg.ZKclose();
	}
}
